package com.jackiechancinema.ssm.controller;

import com.jackiechancinema.ssm.bo.CommoditBO;
import com.jackiechancinema.ssm.bo.OrderBO;
import com.jackiechancinema.ssm.dto.CommoReDTO;
import com.jackiechancinema.ssm.dto.CommoditDetailDTO;
import com.jackiechancinema.ssm.entity.Commodit;
import com.jackiechancinema.ssm.entity.CommoditHead;
import com.jackiechancinema.ssm.entity.Order;
import com.jackiechancinema.ssm.service.Inte.CommoditService;
import com.jackiechancinema.ssm.vo.PageVo;
import com.jackiechancinema.ssm.vo.R;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/api/commodit/")
public class CommoditComtroller {
    @Autowired
    private CommoditService commoditService;

//    //查库存
//    @GetMapping("page")
//    public PageVo<Commodit> page(int page, int limit){
//        return commoditService.queryPage(page, limit);
//    }

    //查负责人
    @GetMapping("checkHead")
    public PageVo<CommoditHead> checkHead(int page, int limit){
        return commoditService.checkHead(page, limit);
    }

    //查库存详情
    @GetMapping("pageDetail")
    public PageVo<CommoditDetailDTO> pageDetail(int page, int limit){
        return commoditService.queryPageDetail(page, limit);
    }
    //修改库存
    @PostMapping("update")

    public R update(Commodit commodit){
        return commoditService.update(commodit);
    }

    //修改负责人
    @PostMapping("updateHead")
    public R updateHead(CommoditHead commoditHead){
        return commoditService.updateHead(commoditHead);
    }

    //新增商品
    @PostMapping("save")
    public R save(Commodit commodit){
        return commoditService.save(commodit);
    }

    //新增负责人
    @PostMapping("head")
    public R headAdd(CommoditHead commoditHead){
        return commoditService.headAdd(commoditHead);
    }

    //删除商品
    @PostMapping("delete")
    public R delet(int commoditId){
        return commoditService.delete(commoditId );
    }

    //删除负责人
    @PostMapping("deleteHead")
    public R deleteHead(int commoditHeadId){

        return commoditService.deleteHead(commoditHeadId );
    }

    //交易记录
    @GetMapping("recording")
    public PageVo<CommoReDTO> recording(int page, int limit){
        return commoditService.queryRecording(page, limit);
    }

//--------------------------------------------------------------------------------------------------
    //仓库条件查询
    @GetMapping("page")
    public PageVo<Commodit> page(CommoditBO commoditBO){
    return commoditService.page(commoditBO);
}

    //文件上传
    @PostMapping("batchadd")
    public R batch(MultipartFile file){
        System.out.println("2");
        return commoditService.batchadd(file);
    }


    @GetMapping("download")
    public void download(CommoditBO o, HttpServletResponse response){
        commoditService.exportExcel(o,response);
    }


}
